package com.ymttest.datadriver;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import com.ymttest.utils.MapUtil;

public class CaseExecute {
	
	public static void executeAndCheck(ImportData importData,GlobalData globalData) {
		CaseExecuteFlow caseExecuteFlow = new CaseExecuteFlowImpl(importData,globalData);
		caseExecuteFlow.beforeCall();
		caseExecuteFlow.callbeforeApis();
		caseExecuteFlow.callApi();
		caseExecuteFlow.commonCheck();
		caseExecuteFlow.userDefinedCheck();
		caseExecuteFlow.afterCall(); 
	}

	public static void executeAndCheck(List<ImportData> importDatas,GlobalData globalData){
		importDatas.forEach(i->executeAndCheck(i,globalData));
	}
	
	public static void executeAllAndCheck(List<Map<String,String>> mapList,GlobalData globalData){
		mapList.forEach(map->{
			executeAndCheck(new ImportDataFromExcelImpl(mapList,map),globalData);
		});
	}

	public static JSONObject execute(ImportData importData,GlobalData globalData) {
		CaseExecuteFlow caseExecuteFlow = new CaseExecuteFlowImpl(importData,globalData);
		caseExecuteFlow.callbeforeApis();
		JSONObject ret = caseExecuteFlow.callApi();
		caseExecuteFlow.commonCheck();
		caseExecuteFlow.userDefinedCheck();
		return ret;
	}
	
	public static List<JSONObject> execute(List<ImportData> importDatas,GlobalData globalData){
		 List<JSONObject> ret = new ArrayList<JSONObject>();
		 importDatas.forEach(i-> ret.add(execute(i,globalData)));
		 return ret;
	}
	
	
	
	
	
	public static void main(String[] args) throws Exception {
/*		Logger.createResultFile("ddd");
		Logger.start(true,"dd22");
		Logger.comment("dddd1");
		Logger.generateResult("dd3");
		*/
		System.out.println(System.getProperty("user.dir")+"\\resource\\TestData.xls");
		
	    File file = new File(System.getProperty("user.dir")+"\\resource\\TestData.xls");
   	

		//data for MySql
		GlobalData globalData = new GlobalDataFromExcelImpl(file, 1);
		ImportData importData = new ImportDataFromDBImpl(10004);
		executeAndCheck(importData,globalData);
		
		
		
		
		
		
		
		
		
		
		
		
		
/*	   List<Map<String,String>> mapList = ExcelOperate.getDataAsMap(file,0);
		ImportData importData = new ImportDataFromExcelImpl(mapList,mapList.get(0));*/

		
		
		
		
		
		//executeAndCheck(aDatas,globalData);
		//executeAllAndCheck(mapList, globalData);
		//System.out.println(hostNameReverasl("sellerproduct.iapi.ymatou.com"));

		
		
	}
		

		
}
